package com.xiyu.service.controller.admin.office;
import com.xiyu.service.vo.office.space.SpaceGetGroupTypeInfoOutput;
import com.xiyu.service.vo.office.space.SpaceSingleGetOutput;
import com.xiyu.service.vo.office.space.SpaceUpdateInput;
import com.xiyu.service.vo.office.space.SpaceCreateInput;
import com.xiyu.service.vo.office.space.SpacePageQueryOutput;
import com.xiyu.service.vo.office.space.SpacePageQueryInput;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import jakarta.validation.*;

import java.util.*;

import com.xiyu.service.framework.web.web.core.pojo.PageResult;
import com.xiyu.service.framework.web.web.core.pojo.CommonResult;
import static com.xiyu.service.framework.web.web.core.pojo.CommonResult.success;

import com.xiyu.service.framework.excel.core.util.ExcelUtils;

import com.xiyu.service.framework.operateLog.core.annotations.OperateLog;
import static com.xiyu.service.framework.operateLog.core.enums.OperateTypeEnum.*;

import com.xiyu.service.service.office.SpaceService;

@Tag(name = "办公用房管理")
@RestController
@RequestMapping("/office/space")
@Validated
public class SpaceController {

    @Resource
    private SpaceService spaceService;

    @GetMapping("/page-query")
    @Operation(summary = "分页查询办公用房")
    @PreAuthorize("@ss.hasPermission('office:space:query')")
    public CommonResult<PageResult<SpacePageQueryOutput>> pageQuery(@Valid SpacePageQueryInput inputVO) {
        return success(spaceService.pageQuery(inputVO));
    }

    @PostMapping("/create")
    @Operation(summary = "新增办公用房")
    @PreAuthorize("@ss.hasPermission('office:space:create')")
    public CommonResult<Long> create(@Valid @RequestBody SpaceCreateInput inputVO) {
        return success(spaceService.create(inputVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新办公用房")
    @PreAuthorize("@ss.hasPermission('office:space:update')")
    public CommonResult<Boolean> update(@Valid @RequestBody SpaceUpdateInput inputVO) {
        return success(spaceService.update(inputVO));
    }

    @GetMapping("/single-get")
    @Operation(summary = "获取单个办公用房")
    @Parameter(name = "id", description = "办公用房主键ID", example = "")
    public CommonResult<SpaceSingleGetOutput> singleGet(@RequestParam("id") Long id) {
        return success(spaceService.singleGet(id));
    }


    @GetMapping("/get-group-type-info")
    @Operation(summary = "获取按办公室类型聚合的信息")
    public CommonResult<List<SpaceGetGroupTypeInfoOutput>> getGroupTypeInfo() {
        return success(spaceService.getGroupTypeInfo());
    }

}
